from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-03 14:02:31.286756
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 03, Aug, 2022
Time: 14:02:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0136
Nobs: 737.000 HQIC: -50.3589
Log likelihood: 9315.32 FPE: 1.08460e-22
AIC: -50.5757 Det(Omega_mle): 9.60708e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297580 0.055943 5.319 0.000
L1.Burgenland 0.107719 0.036977 2.913 0.004
L1.Kärnten -0.106935 0.019598 -5.456 0.000
L1.Niederösterreich 0.207394 0.077252 2.685 0.007
L1.Oberösterreich 0.108367 0.075439 1.436 0.151
L1.Salzburg 0.254361 0.039518 6.437 0.000
L1.Steiermark 0.042190 0.051568 0.818 0.413
L1.Tirol 0.108901 0.041833 2.603 0.009
L1.Vorarlberg -0.062310 0.036008 -1.730 0.084
L1.Wien 0.047764 0.066691 0.716 0.474
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057423 0.116906 0.491 0.623
L1.Burgenland -0.031999 0.077273 -0.414 0.679
L1.Kärnten 0.047044 0.040956 1.149 0.251
L1.Niederösterreich -0.176579 0.161438 -1.094 0.274
L1.Oberösterreich 0.407821 0.157648 2.587 0.010
L1.Salzburg 0.287852 0.082582 3.486 0.000
L1.Steiermark 0.108101 0.107763 1.003 0.316
L1.Tirol 0.311265 0.087421 3.561 0.000
L1.Vorarlberg 0.025761 0.075247 0.342 0.732
L1.Wien -0.029308 0.139367 -0.210 0.833
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189108 0.028704 6.588 0.000
L1.Burgenland 0.090232 0.018973 4.756 0.000
L1.Kärnten -0.008872 0.010056 -0.882 0.378
L1.Niederösterreich 0.258793 0.039637 6.529 0.000
L1.Oberösterreich 0.139589 0.038707 3.606 0.000
L1.Salzburg 0.045546 0.020276 2.246 0.025
L1.Steiermark 0.021665 0.026459 0.819 0.413
L1.Tirol 0.093120 0.021464 4.338 0.000
L1.Vorarlberg 0.055696 0.018475 3.015 0.003
L1.Wien 0.116277 0.034219 3.398 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108560 0.029148 3.725 0.000
L1.Burgenland 0.045741 0.019266 2.374 0.018
L1.Kärnten -0.014128 0.010211 -1.384 0.166
L1.Niederösterreich 0.189025 0.040250 4.696 0.000
L1.Oberösterreich 0.302332 0.039305 7.692 0.000
L1.Salzburg 0.109990 0.020590 5.342 0.000
L1.Steiermark 0.104445 0.026868 3.887 0.000
L1.Tirol 0.106118 0.021796 4.869 0.000
L1.Vorarlberg 0.068715 0.018761 3.663 0.000
L1.Wien -0.021566 0.034748 -0.621 0.535
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125680 0.053115 2.366 0.018
L1.Burgenland -0.049989 0.035108 -1.424 0.154
L1.Kärnten -0.040916 0.018608 -2.199 0.028
L1.Niederösterreich 0.167948 0.073348 2.290 0.022
L1.Oberösterreich 0.140326 0.071626 1.959 0.050
L1.Salzburg 0.289250 0.037520 7.709 0.000
L1.Steiermark 0.035768 0.048961 0.731 0.465
L1.Tirol 0.163696 0.039719 4.121 0.000
L1.Vorarlberg 0.101831 0.034188 2.979 0.003
L1.Wien 0.068438 0.063320 1.081 0.280
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055072 0.042226 1.304 0.192
L1.Burgenland 0.039391 0.027911 1.411 0.158
L1.Kärnten 0.050999 0.014793 3.448 0.001
L1.Niederösterreich 0.217037 0.058310 3.722 0.000
L1.Oberösterreich 0.296452 0.056942 5.206 0.000
L1.Salzburg 0.044011 0.029828 1.475 0.140
L1.Steiermark 0.001290 0.038924 0.033 0.974
L1.Tirol 0.143396 0.031576 4.541 0.000
L1.Vorarlberg 0.072384 0.027179 2.663 0.008
L1.Wien 0.080743 0.050339 1.604 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171192 0.050473 3.392 0.001
L1.Burgenland -0.002379 0.033361 -0.071 0.943
L1.Kärnten -0.062701 0.017682 -3.546 0.000
L1.Niederösterreich -0.080847 0.069698 -1.160 0.246
L1.Oberösterreich 0.192359 0.068062 2.826 0.005
L1.Salzburg 0.058157 0.035653 1.631 0.103
L1.Steiermark 0.234931 0.046525 5.050 0.000
L1.Tirol 0.498722 0.037743 13.214 0.000
L1.Vorarlberg 0.046600 0.032487 1.434 0.151
L1.Wien -0.053867 0.060170 -0.895 0.371
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160212 0.058227 2.752 0.006
L1.Burgenland -0.008036 0.038487 -0.209 0.835
L1.Kärnten 0.065657 0.020398 3.219 0.001
L1.Niederösterreich 0.202421 0.080406 2.517 0.012
L1.Oberösterreich -0.066468 0.078518 -0.847 0.397
L1.Salzburg 0.208711 0.041131 5.074 0.000
L1.Steiermark 0.122794 0.053673 2.288 0.022
L1.Tirol 0.073500 0.043541 1.688 0.091
L1.Vorarlberg 0.120990 0.037478 3.228 0.001
L1.Wien 0.121648 0.069414 1.753 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359586 0.033437 10.754 0.000
L1.Burgenland 0.007178 0.022101 0.325 0.745
L1.Kärnten -0.023698 0.011714 -2.023 0.043
L1.Niederösterreich 0.216022 0.046173 4.679 0.000
L1.Oberösterreich 0.199012 0.045089 4.414 0.000
L1.Salzburg 0.043723 0.023619 1.851 0.064
L1.Steiermark -0.013464 0.030822 -0.437 0.662
L1.Tirol 0.104994 0.025003 4.199 0.000
L1.Vorarlberg 0.070766 0.021522 3.288 0.001
L1.Wien 0.037885 0.039861 0.950 0.342
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039506 0.139448 0.191362 0.151031 0.117491 0.103319 0.063451 0.216548
Kärnten 0.039506 1.000000 -0.007552 0.132406 0.039207 0.094308 0.433035 -0.054024 0.097349
Niederösterreich 0.139448 -0.007552 1.000000 0.333819 0.141573 0.292875 0.094933 0.179320 0.313320
Oberösterreich 0.191362 0.132406 0.333819 1.000000 0.228562 0.324804 0.176119 0.166237 0.261366
Salzburg 0.151031 0.039207 0.141573 0.228562 1.000000 0.142135 0.112444 0.145562 0.124279
Steiermark 0.117491 0.094308 0.292875 0.324804 0.142135 1.000000 0.145935 0.137528 0.071584
Tirol 0.103319 0.433035 0.094933 0.176119 0.112444 0.145935 1.000000 0.112336 0.143389
Vorarlberg 0.063451 -0.054024 0.179320 0.166237 0.145562 0.137528 0.112336 1.000000 -0.000111
Wien 0.216548 0.097349 0.313320 0.261366 0.124279 0.071584 0.143389 -0.000111 1.000000